package cn.wolfcode.shop.web.mq;

import cn.wolfcode.shop.mq.MQDestination;
import cn.wolfcode.shop.redis.SeckillGoodKeyPrefix;
import cn.wolfcode.shop.service.ISeckillService;
import cn.wolfcode.shop.web.controller.SeckillController;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.jms.annotation.JmsListener;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.TextMessage;

public class MQReceiver {
    @Reference
    private ISeckillService seckillService;

    /**
     * 通过订阅发布的信息,更新本地标记
     * @param message
     * @throws JMSException
     */
    @JmsListener(destination = MQDestination.CANCEL_LOCAL_SIGN_TOPIC,containerFactory = "topicListenerFactory")
    public void receiveCancelLocalSignTopic(Message message) throws JMSException {
        if(message instanceof TextMessage){
            TextMessage textMessage = (TextMessage) message;
            Long goodId = Long.valueOf(textMessage.getText());
            SeckillController.localSign.put(SeckillGoodKeyPrefix.GOOD_STOCK+goodId,false);
        }
    }
}
